package com.qimu.saiyou.model.vo;

import cn.hutool.json.JSONUtil;
import com.qimu.saiyou.model.entity.Team;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 帖子视图
 *
 *@author: FeiXiang
 *
 */
@Data
public class TeamVO implements Serializable {

    private static final long serialVersionUID = -4578891853558315271L;
    private Long id;
    private String teamName;
    private String teamAvatarUrl;

    private List<String> tagList;

    private List<String> wantToTagList;

    private Integer maxNum;

    private Integer teamStatus;

    private Date createTime;

    private String announce;

    private UserVO teamLeader;
    private UserVO teamCaptain;
    private List<UserVO> teamUserList;
    private Long currentCompetitionId;
    private Long competeId;

    /**
     * 包装类转对象
     *
     * @param teamVO
     * @return
     */
    public static Team voToObj(TeamVO teamVO) {
        if (teamVO == null) {
            return null;
        }
        Team team = new Team();
        BeanUtils.copyProperties(teamVO, team);
        List<String> tagList = teamVO.getTagList();
        List<String> wantToTagList = teamVO.getWantToTagList();
        team.setTags(JSONUtil.toJsonStr(tagList));
        team.setWantToTags(JSONUtil.toJsonStr(wantToTagList));
        return team;
    }

    /**
     * 对象转包装类
     *
     * @param team
     * @return
     */
    public static TeamVO objToVo(Team team) {
        if (team == null) {
            return null;
        }
        TeamVO teamVO = new TeamVO();
        BeanUtils.copyProperties(team, teamVO);
        teamVO.setTagList(JSONUtil.toList(team.getTags(), String.class));
        teamVO.setWantToTagList(JSONUtil.toList(team.getWantToTags(), String.class));
        return teamVO;
    }
}
